package com.partners.controller;

import com.partners.annotation.BeanValid;
import com.partners.annotation.SimpleParam;
import com.partners.constant.ErrorMessageEnum;
import com.partners.dao.dto.PointInputDTO;
import com.partners.dao.dto.PointsOutputDTO;
import com.partners.model.ApiResult;
import com.partners.model.BusinessException;
import com.partners.model.Paging;
import com.partners.service.PointsService;
import com.partners.utils.ApiResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 积分管理
 * @author liangyongle
 * @date 2018-12-20
 */
@RestController
@RequestMapping("points")
@Slf4j
public class PointsController {

    @Resource
    private PointsService pointsService;


    /**
     * 获取积分列表
     * @param pointInputDTO PointInputDTO
     * @return Object
     */
    @PostMapping("points_list")
    public ApiResult getPointsList(@BeanValid @RequestBody Paging paging, @BeanValid @RequestBody PointInputDTO pointInputDTO){
        Map<String,Object> list = pointsService.getPointsList(paging,pointInputDTO);
        return ApiResultUtil.ok(list);
    }


    /**
     * 获取积分详情
     * @param id Integer
     * @return Object
     */
    @PostMapping("points_detail")
    public ApiResult getPointsDetail(@SimpleParam("id") Integer id){
        if(id == null){
            throw BusinessException.of(ErrorMessageEnum.ID_NOT_FOUND);
        }
        PointsOutputDTO detail = pointsService.getPointsDetail(id);
        return ApiResultUtil.ok(detail);
    }


}
